home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / recover / setupEndOfLog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.3 KB  |  219 lines

  1. /*
  2.  *   $RCSfile: setupEndOfLog.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:55 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37. #include "sysdefs.h"
  38. #include "ess.h"
  39. #include "checking.h"
  40. #include "trace.h"
  41. #include "error.h"
  42. #include "list.h"
  43. #include "pool.h"
  44. #include "tid.h"
  45. #include "io.h"
  46. #include "lock.h"
  47. #include "object.h"
  48. #include "msgdefs.h"
  49. #include "thread.h"
  50. #include "semaphore.h"
  51. #include "latch.h"
  52. #include "link.h"
  53. #include "lsn.h"
  54. #include "bf.h"
  55. #include "volume.h"
  56. #include "openlog.h"
  57. #include "trans.h"
  58. #include "logrecs.h"
  59. #include "threadstate.h"
  60. #include "util_funcs.h"
  61. #include "log_intfuncs.h"
  62. #include "log_extfuncs.h"
  63. #include "recover_intfuncs.h"
  64. #include "recover_extfuncs.h"
  65. #include "trans_extfuncs.h"
  66. #include "bf_extfuncs.h"
  67. #include "thread_funcs.h"
  68. #include "thread_globals.h"
  69. #include "log_globals.h"
  70.  
  71.  
  72.  void
  73. setupEndOfLog (
  74.  
  75.     register LSNOFFSET        lastLSN,
  76.     BOOL                    formatPage 
  77. )
  78. {
  79.  
  80.     GROUPLINK        *tailLink;
  81.     PAGEHASH        *tailBuffer;
  82.     LOGPAGEHDR        *pageHeader;
  83.     LOGPAGEHDR        *endHeader;
  84.     PID                pid;
  85.     OPENLOG            *openLog;
  86. #ifdef DEBUG 
  87.     LSN                debugLSN;
  88. #endif
  89.  
  90.  
  91.     TRPRINT(TR_LOG|TR_RECOVER, TR_LEVEL_1, ("lastLSN:%d", lastLSN));
  92.  
  93.     /*
  94.      *    get a pointer to the openlog structure
  95.      */
  96.     openLog = &OpenLog;
  97.  
  98.     /*
  99.      *    setup the tail page of the log
  100.      */
  101.     openLog->tailPid = LSN_TO_LOG_PAGE(lastLSN, openLog);
  102.     openLog->tailLSN = lastLSN;
  103.     TRPRINT(TR_LOG|TR_RECOVER, TR_LEVEL_1, ("tailPid:%d", openLog->tailPid));
  104.  
  105.     /*
  106.      *    create the pid
  107.      */
  108.     pid.volid = openLog->volid;
  109.     pid.page  = LOG_PAGE_TO_BLOCK(openLog->tailPid, openLog);
  110.  
  111.     /*
  112.      *    read the new page
  113.      */
  114.     if ((tailLink = bf_ReadPage(openLog->writeGroup, &pid,
  115.                                 openLog->page2size, BF_NOREAD)) == NULL)    {
  116.  
  117.         SM_ERROR(TYPE_FATAL, Active->errno);
  118.     }
  119.  
  120.     /*
  121.      *    Unfix the page.  The current page does not have to be fixed as
  122.      *    the semaphore on the log protects the currently active page.  This
  123.      *    is an important assumption that will need to be maintained.
  124.      */
  125.     bf_UnfixPage(tailLink, BF_DEFAULT, FALSE);
  126.  
  127.     /*
  128.      *    record the pointer
  129.      */
  130.     tailBuffer = tailLink->pageHash;
  131.  
  132.     /*
  133.      *    mark that the buffer is a log buffer
  134.      */
  135.     PSET_PAGE_TYPE(tailBuffer, PAGE_LOG);
  136.  
  137.     /*
  138.      *    save the new buffer
  139.      */
  140.     openLog->tailBuffer = tailBuffer;
  141.     openLog->tailLink    = tailLink;
  142.  
  143.     /*
  144.      *    check to make sure the first mark and the force mark are zero
  145.      */
  146.     SM_ASSERT(LEVEL_3, ((tailBuffer->forceMark == 0) && (tailBuffer->firstMark == 0)));
  147.  
  148.     /*
  149.      *    get a pointer to the page header
  150.      */
  151.     pageHeader = (LOGPAGEHDR *) tailBuffer->bufFrame;
  152.     endHeader  = (LOGPAGEHDR *) (((char *) pageHeader) + openLog->lastUsableByte);
  153.  
  154.     /*
  155.      *    check the log page numbers
  156.      */
  157.     SM_ASSERT(LEVEL_1, pageHeader->pageNumber == openLog->tailPid);
  158.     SM_ASSERT(LEVEL_1, endHeader->pageNumber == openLog->tailPid);
  159.  
  160.     /*
  161.      *    format the page if it is clean
  162.      */
  163.     if (formatPage)    {
  164.  
  165.         TRPRINT(TR_LOG|TR_RECOVER, TR_LEVEL_2, ("formatting page"));
  166.  
  167. #ifdef JUNK
  168.         /*
  169.          *    check to see if the log has wrapped
  170.          */
  171.         if (openLog->tailPid == 0)    {
  172.  
  173.             openLog->wrapCount++;
  174.         }
  175. #endif JUNK
  176.  
  177.         /*
  178.          *    zero out the pge
  179.          */
  180.         bzero(tailBuffer->bufFrame, (int) openLog->pageSize);
  181.  
  182.         /*
  183.          *    initialize the header on the page
  184.          */
  185.         pageHeader->magic       = LOGPAGE_MAGIC;
  186.         pageHeader->wrapCount  = openLog->wrapCount;
  187.         pageHeader->lastRecord = NULL_LAST_RECORD;
  188.         pageHeader->pageNumber = openLog->tailPid;
  189.  
  190.         /*
  191.          *    initialize the header on the page
  192.          */
  193.         endHeader->magic      = LOGPAGE_MAGIC;
  194.         endHeader->wrapCount  = openLog->wrapCount;
  195.         endHeader->lastRecord = NULL_LAST_RECORD;
  196.         endHeader->pageNumber = openLog->tailPid;
  197.  
  198.         /*
  199.          *    dirty the page
  200.          */
  201. #ifdef DEBUG 
  202.         waitSemaphore(&(tailBuffer->semaphore));
  203. #endif
  204.         DIRTY_PAGE(tailBuffer);
  205. #ifdef DEBUG 
  206.         signalSemaphore(&(tailBuffer->semaphore));
  207. #endif
  208. #ifdef DEBUG 
  209.         /* make sure we don't overwrite important log records */
  210.         debugLSN.offset = openLog->tailLSN;
  211.         debugLSN.wrapCount = openLog->wrapCount;
  212.         debugLSN.wrapCount--;
  213.         if(compareLSN(&debugLSN, &OldestDirtyPageLSN) >= 0) {
  214.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  215.         }
  216. #endif
  217.     }
  218. }
  219.